﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

/* Generated with http://xmltocs.com/ */
namespace EDMXParserV1
{
    public class EntityType
    {
        public EntityType()
        {
            Keys = new List<string>();
            Properties = new List<Property>();
            NavigationProperties = new List<NavigationProperty>();
        }

        public String Name { get; set; }
        public List<String> Keys { get; set; }
        public List<Property> Properties { get; set; }
        public List<NavigationProperty> NavigationProperties { get; set; }

        public string GetTypeName( String ID )
        {
            foreach (Property item in Properties )
	        {
                if ( ID == item.Name )
                {
                    return item.Type;
                }
	        }
            return "String";
        }

        public static EntityType New(System.Xml.XmlNode Node)
        {
            EntityType EntityType = new EntityType();

            foreach (XmlAttribute Attribute in Node.Attributes)
            {
                switch (Attribute.Name)
                {
                    case "Name":
                        EntityType.Name = Attribute.Value;
                        break;

                    default:
                        Globals.AttributeSwitchCoder(Attribute);
                        break;
                }

            }

            foreach (XmlNode ChildNode in Node.ChildNodes)
            {
                switch (ChildNode.Name)
                {
                    case "Key":
                        foreach (XmlNode KeyNode in ChildNode.ChildNodes)
                        {
                            String KeyName = ChildNode.ChildNodes[0].Attributes["Name"].Value;
                            EntityType.Keys.Add(KeyName);
                        }
                        break;
                    case "Property":
                        Property Property = Property.New( ChildNode );
                        EntityType.Properties.Add(Property);
                        break;
                    case "NavigationProperty":
                        NavigationProperty NavigationProperty = NavigationProperty.New(ChildNode);
                        EntityType.NavigationProperties.Add(NavigationProperty);
                        break;
                    default:
                        Globals.NodeSwitchCoder(ChildNode);
                        break;
                }
            }

            return EntityType;
        }
    }
}
